<?php
	class UserController extends BaseController{
		public function getSelect($shop_id){
			try{
					echo $json = json_encode(Users::Select($shop_id));
			}
			catch(Exception $e){
				return ErrorResponse::SendErrorMessage($e->getMessage());
			}
		}
		public function postInsert(){
	    	//checks the information input
		   try{
			   $input=Input::json()->all();

	           $shop_id=InputHelper::getInput($input,'shop_id');

	            $name=InputHelper::getInput($input,'name');

	            $address=InputHelper::getInput($input,'address');

	            $birthdate=InputHelper::getInput($input,'birthdate');

	            $phone=InputHelper::getInput($input,'phone','');

	            $email=InputHelper::getInput($input,'email','');

	            $people_id=InputHelper::getInput($input,'people_id');

	            $salary=InputHelper::getInput($input,'salary','');

	            $username=InputHelper::getInput($input,'username','');

	            $password=InputHelper::getInput($input,'password');

	            $comment=InputHelper::getInput($input,'comment','');
	        }
        	catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	        // edit to database 
		    try{
		    	
		    	if($staffid = Users::Insert($name,$address,$birthdate,$phone,$email,$people_id,$salary,$shop_id,$username,$password,$comment))
	        	{
	        		
	        		//echo json_encode(array('id'=>$id));
                	return Response::json(array('status'=>'success'));
                //	return (Users::Insert_accounts($username,$password,$staff_id));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		}
		public function postEdit(){
	    	//checks the information input
			try{
			   $input=Input::json()->all();

	           $staff_id=InputHelper::getInput($input,'staff_id');

	            $name=InputHelper::getInput($input,'name');

	            $address=InputHelper::getInput($input,'address');

	            $birthdate=InputHelper::getInput($input,'birthdate');

	            $phone=InputHelper::getInput($input,'phone','');

	            $email=InputHelper::getInput($input,'email','');

	            $people_id=InputHelper::getInput($input,'people_id');

	            $salary=InputHelper::getInput($input,'salary','');
	        }
        	catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	        // edit to database 
		    try{
		    	if(Users::Edit($name,$address,$birthdate,$phone,$email,$people_id,$salary,$staff_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
		}
		public function postDeletedata($staff_id){
	        try{
	        	if(Users::Deletedata($staff_id))
	        	{
	        		return Response::json(array('status'=>'success'));
	        	}	             
	        }
	        catch(Exception $e)
	        {
	            return ErrorResponse::SendErrorMessage($e->getMessage());
	        }
	    }
	    public function postChangePassword($staff_id){
	    	if(Input::has('password_old'))
		        {
		            $password_old=Input::get('password_old');
		        }
	        else
		        {
		            return ErrorResponse::SendErrorMessage('Warehourses password invalid');
		        }
		        if(Input::has('password_new'))
		        {
		            $password_new=Input::get('password_new');
		        }
	        else
		        {
		            return ErrorResponse::SendErrorMessage('Warehourses password invalid');
		        }
	    	try{
	    		if(Users::ChangePassword($password_old,$password_new,$staff_id)){
	    			return Response::json(array('status'=>'success'));
	    		}
	    	}catch (Exception $e){
	    		return ErrorResponse::SendErrorMessage($e->getMessage());
	    	}
	    }

	}
?>